package cn.rongdao.jrkabao.ui.loan.adapter.viewholder;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mifengkong.frtools.ui.adapter.recyclerview.FRBaseRecyclerViewHolder;
import com.mifengkong.frtools.util.FRImageLoad;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.loan.ApplySuccessBean;


/**
 * Created by jack on 2017/8/24
 */

public class ApplySuccessViewHolder extends FRBaseRecyclerViewHolder<ApplySuccessBean.ReaultListBean.ProductListBean> {

    private final ImageView mTag;
    private final ImageView mIcon;
    private final TextView mName;
    private final TextView mDesc;
    private final TextView mAmount;
    private final View mShadow;
    private final View mRootView;

    private int count;

    public ApplySuccessViewHolder(View view, final OnApplySuccessClickListener onApplySuccessClickListener, int count) {
        super(view);
        this.count = count;
        mIcon = findView(R.id.impna_icon);
        mName = findView(R.id.impna_name);
        mDesc = findView(R.id.impna_desc);
        mAmount = findView(R.id.impna_amount);
        mTag = findView(R.id.impna_tag);
        mShadow = findView(R.id.impna_center_view);
        mRootView = findView(R.id.impna_root_view);

        mRootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != onApplySuccessClickListener) {
                    onApplySuccessClickListener.onItemClick(v, getLayoutPosition());
                }
            }
        });
    }

    @Override
    protected void onItemDataUpdated(ApplySuccessBean.ReaultListBean.ProductListBean productListBean) {
        mRootView.setVisibility(View.VISIBLE);
        FRImageLoad.loadImage(productListBean.getOrg_pic(), mIcon);
        FRImageLoad.loadImage(productListBean.getIs_hot_pic(), mTag);
        mName.setText(productListBean.getOrg_name());
        mDesc.setText(productListBean.getOrg_des());
        mAmount.setText(TextUtils.concat(productListBean.getGrade_scope_lowest(), " - ", getHightAMount(productListBean).toString()));
        if (getLayoutPosition() == count - 1) {
//            viewLine.setVisibility(View.GONE);
        }
    }

    private String getHightAMount(ApplySuccessBean.ReaultListBean.ProductListBean productListBean) {
        try {
            int amount = Integer.parseInt(productListBean.getGrade_scope_highest());
            return amount / 10000 == 0 ? String.valueOf(amount) : TextUtils.concat(String.valueOf(amount / 10000), "万").toString();
        } catch (Exception e) {

        }
        return "";
    }


    public interface OnApplySuccessClickListener {
        void onItemClick(View view, int position);
    }
}